<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserPointRecord
 *
 * @property int $id
 * @property int $uid 用户ID
 * @property float $points 积分
 * @property string|null $body 描述
 * @property string $from 获得方式
 * @property int $type 积分类型，1=激活，0=非激活
 * @property int $trade_type 交易类型,1=收入，0=支出
 * @property int $created_at 获得时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord whereBody($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord whereFrom($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord wherePoints($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord whereTradeType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserPointRecord whereUid($value)
 * @mixin \Eloquent
 * @property-read \App\Models\User $user
 */
class UserPointRecord extends Model
{
    protected $table = 'user_point_record';
    protected $primaryKey = 'id';
    protected $guarded = ['id'];

    public $timestamps = false;

    public static function boot()
    {
        parent::boot(); // TODO: Change the autogenerated stub
        static::creating(function ($model){
            if (!$model->created_at) $model->created_at = time();
        });
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'uid', 'uid');
    }
}
